<?php
require 'common.php';
class IndexController extends CommonController{

    function index()
    {
        $articles = $this->getAll("select article.*,tag.name as tag_name  from article left join tag on article.tag_id = tag.id");
        //  dump($articles);exit;

        $this->assign("articles",$articles);
        $this->display("index.html");
    }

    /**
     * 显示某条具体详情
     */
    function showInfo(){
        $id = $_GET["id"];

     $article = $this->getOne("select * from article where id= '$id'");
        $tag =  $this->getOne("select t.name from tag t left join article a on t.id=a.tag_id where a.id='$id' ");

        $this->assign("article",$article);
        $this->assign("tag",$tag);
        $this->display("article.html");
//require 'templates/article.html';

        }

    function getInfoByTag(){
        $id =$_GET["id"];

        $t =$this-> getOne("select * from tag where id='$id'");

        $articles = $this->getAll("select article.* ,tag.name as tag_name from article left join tag on article.tag_id=tag.id where tag_id ='$id'");





        $this->assign("t",$t);
        $this->assign("articles",$articles);

        $this->display("tag.html");
    }

}

$action = isset($_GET["action"])?$_GET["action"]:"index";

$index = new IndexController();

$index->$action();
